package digimon.organism;

import java.util.LinkedList;

import digimon.organism.instructions.Instruction;

public class Organism {
	public static final int INSTRUCTION_LIST_SIZE = 20;
	/**
	 * 0 - generic organism <br>
	 * 1 - vision organism <br>
	 * 2 - Communication organism <br>
	 * 3 - Motor organism <br>
	 */
	private int ORG_TIPE;
	protected LinkedList<Instruction> instructions;
	private int instructionPointer;
	private int priority;
	private boolean timeToReproduce;


	public Organism(){
		setTimeToReproduce(false);
		setInstructionPointer(0);
		setPriority(0);
		setORG_TIPE(0);
		setInstructions(new LinkedList<Instruction>());
		
		// Build the list, taking random instructions 
		for(int count = 0; count < INSTRUCTION_LIST_SIZE ; count++){
			instructions.add(new Instruction());
		}
	}
	

	/**
	 * Need to make this constructor to use by child organisms <br> 
	 * we don't need all this variables set in child organisms <br>
	 * @param b just to be differenced between default constructor
	 */
	public Organism(boolean b){
		setTimeToReproduce(false);
		setInstructionPointer(0);
		setPriority(0);
	}

	public int getInstructionPointer() {
		return instructionPointer;
	}

	public void setInstructionPointer(int instructionPointer) {
		// Must verify if IP is not larger than admitted
		if(instructionPointer <= INSTRUCTION_LIST_SIZE)
			this.instructionPointer = instructionPointer;
		// If is, its time to reproduce
		else {
			setTimeToReproduce(true);
			this.instructionPointer = 0;
		}
			
	}

	public LinkedList<Instruction> getInstructions() {
		return instructions;
	}

	public void setInstructions(LinkedList<Instruction> instructions) {
		this.instructions = instructions;
	}

	/**
	 * Return the type of this organism <br>
	 * 0 - generic organism <br>
	 * 1 - vision organism <br>
	 * 2 - Communication organism <br>
	 * 3 - Motor organism <br>
	 * @return integer representing organism type
	 */
	public int getORG_TIPE() {
		return ORG_TIPE;
	}

	/**
	 * Set the type of this organism
	 * 0 - generic organism <br>
	 * 1 - vision organism <br>
	 * 2 - Communication organism <br>
	 * 3 - Motor organism
	 */
	public void setORG_TIPE(int oRG_TIPE) {
		ORG_TIPE = oRG_TIPE;
	}

	/**
	 *  Return the priority of this organism<br>
	 * 0 - default priority <br>
	 * 1 - high priority <br>
	 * 2 - super high priority <br>
	 * @return the priority
	 */
	public int getPriority() {
		return priority;
	}

	/**
	 * Set priority of this organism<br>
	 * 0 - default priority <br>
	 * 1 - high priority <br>
	 * 2 - super high priority <br>
	 * @param priority the priority to set
	 */
	public void setPriority(int priority) {
		this.priority = priority;
	}
	
	/**
	 * @return the timeToReproduce
	 */
	public boolean isTimeToReproduce() {
		return timeToReproduce;
	}


	/**
	 * @param timeToReproduce the timeToReproduce to set
	 */
	public void setTimeToReproduce(boolean timeToReproduce) {
		this.timeToReproduce = timeToReproduce;
	}
}
